package com.usian.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.service.AdChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController //以json响应串返回前端  restful风格
//@Controller  //以返回页面路劲
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService adChannelService;

    @Override
    @PostMapping("/list")
    public ResponseResult findAdChannel(@RequestBody ChannelDto dto) {
        return adChannelService.findAdChannel(dto);
    }

    @Override
    @PostMapping("/save")
    public ResponseResult saveAdChannel(@RequestBody AdChannel channel) {
        return adChannelService.saveAdChannel(channel);
    }

    @Override
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    @Override
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adChannelService.deleteById(id);
    }

    @Override
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<AdChannel> channelList = adChannelService.list(Wrappers.<AdChannel>lambdaQuery().eq(AdChannel::getStatus, 1));
        return ResponseResult.okResult(channelList);
    }
}
